<?php require_once('Connections/Insapeca.php'); ?>
<?php defined('_JEXEC') or die('Restricted access'); ?>
<?php
// Load the common classes
require_once('includes/common/KT_common.php');

// Load the tNG classes
require_once('includes/tng/tNG.inc.php');

// Load the KT_back class
require_once('includes/nxt/KT_back.php');

// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("");

// Make unified connection variable
$conn_Insapeca = new KT_connection($Insapeca, $database_Insapeca);

// Start trigger
$formValidation = new tNG_FormValidation();
$formValidation->addField("nm_autor", true, "text", "", "", "", "Por favor, insira um valor.");
$tNGs->prepareValidation($formValidation);
// End trigger

// Make an insert transaction instance
$ins_autor = new tNG_multipleInsert($conn_Insapeca);
$tNGs->addTransaction($ins_autor);
// Register triggers
$ins_autor->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_autor->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_autor->registerTrigger("END", "Trigger_Default_Redirect", 99, "includes/nxt/back.php");
// Add columns
$ins_autor->setTable("autor");
$ins_autor->addColumn("nm_autor", "STRING_TYPE", "POST", "nm_autor");
$ins_autor->setPrimaryKey("id_autor", "NUMERIC_TYPE");

// Make an update transaction instance
$upd_autor = new tNG_multipleUpdate($conn_Insapeca);
$tNGs->addTransaction($upd_autor);
// Register triggers
$upd_autor->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
$upd_autor->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$upd_autor->registerTrigger("END", "Trigger_Default_Redirect", 99, "includes/nxt/back.php");
// Add columns
$upd_autor->setTable("autor");
$upd_autor->addColumn("nm_autor", "STRING_TYPE", "POST", "nm_autor");
$upd_autor->setPrimaryKey("id_autor", "NUMERIC_TYPE", "GET", "id_autor");

// Make an instance of the transaction object
$del_autor = new tNG_multipleDelete($conn_Insapeca);
$tNGs->addTransaction($del_autor);
// Register triggers
$del_autor->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Delete1");
$del_autor->registerTrigger("END", "Trigger_Default_Redirect", 99, "includes/nxt/back.php");
// Add columns
$del_autor->setTable("autor");
$del_autor->setPrimaryKey("id_autor", "NUMERIC_TYPE", "GET", "id_autor");

// Execute all the registered transactions
$tNGs->executeTransactions();

// Get the transaction recordset
$rsautor = $tNGs->getRecordset("autor");
$row_rsautor = mysql_fetch_assoc($rsautor);
$totalRows_rsautor = mysql_num_rows($rsautor);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insapeca</title>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
<script src="includes/nxt/scripts/form.js" type="text/javascript"></script>
<script src="includes/nxt/scripts/form.js.php" type="text/javascript"></script>
<script type="text/javascript">
$NXT_FORM_SETTINGS = {
  duplicate_buttons: false,
  show_as_grid: false,
  merge_down_value: true
}
</script>
</head>

<body>
<?php
	echo $tNGs->getErrorMsg();
?>
<div class="KT_tng" lang="pt">
  <h1>
    <?php 
// Show IF Conditional region1 
if (@$_GET['id_palavra_chave'] == "") {
?>
    <?php echo NXT_getResource("Inserir"); ?>
    <?php 
// else Conditional region1
} else { ?>
    <?php echo NXT_getResource("Atualizar"); ?>
    <?php } 
// endif Conditional region1
?> 
  Autor</h1>
  <div class="KT_tngform">
    <form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
      <?php $cnt1 = 0; ?>
      <?php do { ?>
     <?php $cnt1++; ?>
           <br />
        <?php 
// Show IF Conditional region1 
if (@$totalRows_rsautor > 1) {
?>
          <h2><?php echo NXT_getResource("Gravação"); ?> <?php echo $cnt1; ?></h2>
          <?php } 
// endif Conditional region1
?>
        <table cellpadding="2" cellspacing="0" class="KT_tngtable">
          <tr>
            <td class="KT_th"><label for="nm_autor_<?php echo $cnt1; ?>">Nome Autor(a):</label></td>
            <td><input type="text" name="nm_autor_<?php echo $cnt1; ?>" id="nm_autor_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsautor['nm_autor']); ?>" size="80" maxlength="100" />
              <?php echo $tNGs->displayFieldHint("nm_autor");?> <?php echo $tNGs->displayFieldError("autor", "nm_autor", $cnt1); ?></td>
          </tr>
        </table>
        <input type="hidden" name="kt_pk_autor_<?php echo $cnt1; ?>" class="id_field" value="<?php echo KT_escapeAttribute($row_rsautor['kt_pk_autor']); ?>" />
        <?php } while ($row_rsautor = mysql_fetch_assoc($rsautor)); ?>
      <div class="KT_bottombuttons" lang="pt">
        <div lang="pt">
          <?php 
      // Show IF Conditional region1
      if (@$_GET['id_autor'] == "") {
      ?>
            <input type="submit" name="KT_Insert1" id="KT_Insert1" value="<?php echo NXT_getResource("Inserir"); ?>" />
            <?php 
      // else Conditional region1
      } else { ?>
            <div class="KT_operations">
              <input type="submit" name="KT_Insert1" value="<?php echo NXT_getResource("Inserir a novo"); ?>" onclick="nxt_form_insertasnew(this, 'id_autor')" />
            </div>
            <input type="submit" name="KT_Update1" value="<?php echo NXT_getResource("Atualizar"); ?>" />
            <input type="submit" name="KT_Delete1" value="<?php echo NXT_getResource("Deletar"); ?>" onclick="return confirm('<?php echo NXT_getResource("Você tem certeza?"); ?>');" />
            <?php }
      // endif Conditional region1
      ?>
          <input name="KT_Cancel1" type="reset" onclick="return UNI_navigateCancel(event, 'includes/nxt/back.php')" value="<?php echo NXT_getResource("Cancelar"); ?>" />
        <a href="gerenciaAutor.php" title="Listar" target="_self">Listar</a> </div>
      </div>
    </form>
  </div>
  <br class="clearfixplain" />
</div>
<p>&nbsp;</p>
</body>
</html>